//
//  NSArray+TW.m
//  TWHomework-WeChat
//
//  Created by wzb on 2019/11/15.
//  Copyright © 2019 WZB. All rights reserved.
//

#import "NSArray+TW.h"

@implementation NSArray (TW)

/**
 *  过滤数组元素，将 block 返回 YES 的 item 重新组装成一个数组返回
 */
- (NSArray *)tw_filterWithBlock:(BOOL (^)(id))block
{
    if (!block) {
        return self;
    }
    
    NSMutableArray *result = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < self.count; i++) {
        id item = self[i];
        if (block(item)) {
            [result addObject:item];
        }
    }
    return [result copy];
}

@end
